import { LoadingUtil } from './../../common/loading';
import { BusiserviceProvider } from './../../providers/busiservice/busiservice';
import { UiserviceProvider } from './../../providers/uiservice/uiservice';
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, LoadingController } from 'ionic-angular';

/**
 * Generated class for the OrderPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-order',
  templateUrl: 'order.html',
})
export class OrderPage {
  flag:string="wjd";
  orderlist=[];
  loading:LoadingUtil;
  constructor(public navCtrl: NavController, public navParams: NavParams,public busiservice: BusiserviceProvider, private loadingCtrl: LoadingController, private uiservice: UiserviceProvider) {
    this.loading = new LoadingUtil(this.loadingCtrl);
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad OrderPage');
  }
  addOrder(){
    this.navCtrl.push("OrderaddPage");
  }
  ionViewDidEnter(){
    if(this.flag=="wjd"){
      this.getCusWjOrder();
    }else{
      this.getCusYjOrder();
    }
  }
  getCusWjOrder(){
    this.loading.showLoading();
    this.busiservice.getCusWjOrder().subscribe(
      data => {
        if (data._success) {
          this.orderlist = data.result;
          this.loading.hideLoading();
          //用户id
        } else {
          this.loading.hideLoading();
          this.uiservice.showAlert(data._message);
        }
      }
      ,
      error => {
        this.loading.hideLoading();
        this.uiservice.showAlert("网络异常!");
      }
    );
  }
  getCusYjOrder(){
    this.loading.showLoading();
    this.busiservice.getCusYjOrder().subscribe(
      data => {
        if (data._success) {
          this.orderlist = data.result;
          this.loading.hideLoading();
          //用户id
        } else {
          this.loading.hideLoading();
          this.uiservice.showAlert(data._message);
        }
      }
      ,
      error => {
        this.loading.hideLoading();
        this.uiservice.showAlert("网络异常!");
      }
    );
  }
  orderdetail(orderid){
    this.loading.showLoading();
    this.busiservice.orderDetail(orderid).subscribe(
      data => {
        if (data._success) {
          this.navCtrl.push("OrderdetailPage",{order:data.result});
          this.loading.hideLoading();
          //用户id
        } else {
          this.loading.hideLoading();
          this.uiservice.showAlert(data._message);
        }
      }
      ,
      error => {
        this.loading.hideLoading();
        this.uiservice.showAlert("网络异常!");
      }
    );
  }

}
